package cc.cix.hq.auth.translator;

import cc.cix.hq.common.core.entity.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.oauth2.provider.error.WebResponseExceptionTranslator;
import org.springframework.stereotype.Component;

/**
 * 异常翻译
 *
 * @author cix
 */
@Slf4j
@Component
@SuppressWarnings("all")
public class HqWebResponseExceptionTranslator implements WebResponseExceptionTranslator {

    @Override
    public ResponseEntity<?> translate(Exception e) {
        ResponseEntity.BodyBuilder status = ResponseEntity.status(HttpStatus.BAD_REQUEST);
        log.error(e.getMessage());
        return status.body(Result.fail(e.getMessage()));
    }
}
